import axios from 'axios'

const instance = axios.create({
  // baseURL: 'http://localhost:8081'
  baseURL: 'https://ambitousjun.fun'
})

// 设置响应拦截器
instance.interceptors.response.use(
  res => {
    // 正常返回数据
    return res
  },
  error => {
    if(error.message.includes('timeout')) {
      return Promise.reject(error)
    }
  }
)

// 获取数字广大首页数据
export function getIndex() {
  return instance({
    url: '/api/index',
    method: 'GET'
  })
}

// 发送登录参数
export function login(params) {
  const {ul, pl, rsa, jsessionId, execution, clientId, lt, sfCookie27, year, term} = params
  return instance({
    url: '/api/login',
    method: 'POST',
    data: {
      ul,
      pl,
      lt,
      rsa,
      jsessionId,
      sfCookie27,
      execution,
      clientId,
      year,
      term
    }
  })
}

// 进入教务系统
export function loginEducation(token) {
  return instance({
    url: '/api/education',
    params: {
      CASTGC: token
    }
  })
}

// 获取成绩
export function getGrade(jSessionId, sfCookie18, year, term) {
  return instance({
    url: '/api/grade',
    params: {
      jSessionId,
      sfCookie18,
      year,
      term
    }
  })
}

// 获取考试列表
export function getExam(jSessionId, sfCookie18, year, term) {
  return instance({
    url: '/api/exam',
    params: {
      jSessionId,
      sfCookie18,
      year,
      term
    }
  })
}

// 获取课表
export function getCourse(jSessionId, sfCookie18, year, term) {
  return instance({
    url: '/api/course',
    params: {
      jSessionId,
      sfCookie18,
      year,
      term
    }
  })
}

// 获取学业情况
export function getAcademic(jSessionId, sfCookie18) {
  return instance({
    url: '/api/academic_info',
    params: {
      jSessionId,
      sfCookie18
    }
  })
}